package controller

import (
	"apitestAfterGo/common"
	"apitestAfterGo/domain"
	"apitestAfterGo/dto"
	"apitestAfterGo/service"
	"apitestAfterGo/utils"
	"github.com/kataras/iris/v12/mvc"
)

type TaskRecordController struct {
}

func (t *TaskRecordController) BeforeActivation(b mvc.BeforeActivation) {
	b.Handle("POST", "/findAllRecordsByPage", "FindAllRecordsByPage")
	b.Handle("POST", "/findRecordsBySystemId", "FindRecordsBySystemId")
	b.Handle("DELETE", "/deleteRecordById/{id:int}", "DeleteRecordById")
}

func (t *TaskRecordController) FindAllRecordsByPage(dto dto.TaskRecordPageInputDto) common.Result {
	taskRecords, i := service.TaskRecordServiceImpl.FindAllRecordsByPage(dto)
	pages := utils.GetPages(i, dto.PageSize)
	page := domain.Page{
		Pages:   pages,
		Total:   i,
		Current: dto.Current,
		Size:    dto.PageSize,
		Records: taskRecords,
	}
	return utils.Success(page, "获取测试记录成功!")
}

func (t *TaskRecordController) FindRecordsBySystemId(dto dto.TaskRecordPageInputDto) common.Result {
	taskRecords, i := service.TaskRecordServiceImpl.FindRecordsBySystemId(dto)
	pages := utils.GetPages(i, dto.PageSize)
	page := domain.Page{
		Pages:   pages,
		Total:   i,
		Current: dto.Current,
		Size:    dto.PageSize,
		Records: taskRecords,
	}
	return utils.Success(page, "获取测试记录成功!")
}

func (t *TaskRecordController) DeleteRecordById(id int) common.Result {
	byId := service.TaskRecordServiceImpl.DeleteRecordById(id)
	return utils.Success(byId, "删除测试记录成功")
}
